<html>
<head><meta charset="utf-8"><title>Trying to make `likely` const · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html">Trying to make `likely` const</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202083788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202083788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gary Guo <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202083788">(Jun 26 2020 at 12:37)</a>:</h4>
<p>I tried to make <code>likely</code> and <code>unlikely</code> const in order to address <a href="https://github.com/rust-lang/rust/issues/73731">#73731</a>. Code is at <a href="https://github.com/nbdd0121/rust/tree/checked_opt">https://github.com/nbdd0121/rust/tree/checked_opt</a>.</p>
<p>However this does not compile,  with error <code>intrinsics::unlikely is not yet stable as a const fn</code>, and a help message <code>add #![feature(const_likely)] to the crate attributes to enable</code>. However I did have <code>#![feature(const_likely)]</code> added in src/libcore/lib.rs. Making <code>likely</code> and <code>unlikely</code> use rustc_const_stable obviously fixes this issue, but I don't think that is correct way forward even though they are currently not exposed to user.</p>
<p>Could someone have a look of this issue?</p>



<a name="202087951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202087951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202087951">(Jun 26 2020 at 13:17)</a>:</h4>
<p>you need to use <code>#[allow_internal_unstable(const_likely)]</code> if you want to make a const stable function use unstable const things feature gated by <code>const_likely</code></p>



<a name="202108536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202108536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gary Guo <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202108536">(Jun 26 2020 at 15:56)</a>:</h4>
<p>Seems not working due to <a href="https://github.com/rust-lang/rust/issues/69399">https://github.com/rust-lang/rust/issues/69399</a></p>



<a name="202108902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202108902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202108902">(Jun 26 2020 at 15:59)</a>:</h4>
<p>you can try applying my suggested patch from <a href="https://github.com/rust-lang/rust/pull/69373#issuecomment-591366565">https://github.com/rust-lang/rust/pull/69373#issuecomment-591366565</a></p>



<a name="202108917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202108917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202108917">(Jun 26 2020 at 15:59)</a>:</h4>
<p>not sure if that is still up to date</p>



<a name="202131582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202131582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gary Guo <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202131582">(Jun 26 2020 at 19:24)</a>:</h4>
<p>Thanks. That eliminates some errors, but not all of them. I am digging to see what else is wrong</p>



<a name="202172242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202172242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202172242">(Jun 27 2020 at 07:08)</a>:</h4>
<p>For anyone reading along, there's now a PR at <a href="https://github.com/rust-lang/rust/pull/73778">https://github.com/rust-lang/rust/pull/73778</a></p>



<a name="202172254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Trying%20to%20make%20%60likely%60%20const/near/202172254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Trying.20to.20make.20.60likely.60.20const.html#202172254">(Jun 27 2020 at 07:09)</a>:</h4>
<p><span class="user-mention" data-user-id="303710">@Gary Guo</span> since we're entering new territory here, we have some procedural steps to do before merging the PR</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>